package com.sgzn.sgpay.web.controller;


import com.sgzn.sgpay.model.request.SgsUserUpdateRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.service.SgsUserService;
import com.sgzn.sgpay.web.controller.base.UserBaseController;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.UpdateUserNameRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 用户管理控制器
 * @author zhongzhongyong
 * @version Id: UserManageController.java, v 0.1 2018/4/21 16:05 zhongzhongyong Exp $$
 */
@Slf4j
@Controller
public class UserManageController extends UserBaseController{

    @Resource
    private SgsUserService sgsUserService;
    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    @RequestMapping("/user/updateUserName")
    @ResponseBody
    public SgsResultResponse<String> updateUserName(UpdateUserNameRequest request){
        super.setUserInfo(request);
        return sgsUserService.update(assembleRequest(request));
    }

    private SgsUserUpdateRequest assembleRequest(UpdateUserNameRequest request) {
        SgsUserUpdateRequest target = new SgsUserUpdateRequest();
        target.setUserName(request.getUserName());
        assembleCommonHandle.assembleUserRequest(request, target);
        return target;
    }

}

